<template>
	<div class="userStudyData w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		<div class="label_top">
			<button @click="reBack"><i><&nbsp;</i>返回</button>
			<p>{{peopleTitle}}的学习任务数据</p>
		</div>
		<div class="labelContainer">
			<p class="courseName">课程名称：{{updateTitle}}</p>
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column label="序号" width="55">
					<template slot-scope="scope">{{ scope.row.sort}}</template>
				</el-table-column>
				<el-table-column prop="courseName" label="课程目录"></el-table-column>
				<el-table-column label="学习时长" width="100">
					<template slot-scope="scope">{{ scope.row.completedNum}}</template>
				</el-table-column>
				<el-table-column prop="starttime" label="开始时间" width="170"></el-table-column>
				<el-table-column prop="endtime" label="完成时间" width="170"></el-table-column>
				<el-table-column label="学习状态" width="90">
					<template slot-scope="scope">
						<span v-if="scope.row.status==1">待学习</span>
						<span v-if="scope.row.status==2">学习中</span>
						<span v-if="scope.row.status==3">已完成</span>
					</template>
				</el-table-column>
			</el-table>
			<div class="fenyeMargin">
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	export default {
		data() {
			return {
				peopleTitle:'',
				updateTitle:'',
				userid:'',
				courseid:'',
				tableData:[],
				completedNum:'',
				
				sort:'',
				pagesize: 15,
		        currentpage: 1,
		        total: 1
			}
		},
		methods:{
			getParams() {
				this.userid = this.$route.params.userId;
				this.updateTitle = this.$route.params.updateTitle;
				this.peopleTitle = this.$route.params.peopleTitle;
				this.courseid = this.$route.params.courseid;
				console.log('userStudyData:',this.$route.params);
			},
			getTableList(){
				this.$ajax({
					url: this.$root.jifuUrl + "/getUserPlatformCompulsuryCourseData?"+'page='+this.currentpage+'&num=' +this.pagesize+'&userid='+this.userid+'&courseid='+this.courseid,
					method: 'GET',
					data: {},
					success: res => {
						console.log(res);
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
							for(var i = 0;i<this.tableData.length;i++){
								this.tableData[i].sort=i+1;
								if(this.tableData[i].completedNum==0){
									this.tableData[i].completedNum='';
								}else{
									let mss = this.tableData[i].completedNum;
									var h = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
									var hours=h>=10?h:"0"+h;
									var m = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
									var minutes=m>=10?m:"0"+m;   
									var ss = parseInt((mss % (1000 * 60)) / 1000);
									var seconds=ss>=10?ss:"0"+ss;
									this.tableData[i].completedNum=hours + ":" + minutes + ":" + seconds ;
								}
							}
						}
					}
				});
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				val.forEach(row => {
					this.multipleSelection.push(row.id);
				});
			},
			handleCurrentChange(value) {
				this.currentpage = value;
				this.getTableList();
			},
			reBack(){
				this.$router.go(-1);
			}
		},
		components: {
			alert,
			deleteAlert
		},
		mounted(){
			this.getParams();
			if(this.userid==null){
				this.$store.commit('GET_userStudyData');
				var s =this.$store.state.userStudyData;
				this.userid=s.userid;
				this.updateTitle=s.updateTitle;
				this.peopleTitle = s.peopleTitle;
				this.courseid = s.courseid;
			};
			this.getTableList();
			window.addEventListener("beforeunload",()=>{
				s={
					userid:this.userid,
					updateTitle:this.updateTitle,
					peopleTitle:this.peopleTitle,
					courseid:this.courseid
				};
				this.$store.commit('SET_userStudyData', s);
			});
		}
	}
</script>

<style>
	.userStudyData{padding-bottom: 100px;}
	.userStudyData .courseName{margin-bottom: 30px;}
</style>